package com.git.hui.yinshua.api.model.permission;

import lombok.Getter;

/**
 * @author YiHui
 * @date 2024/6/7
 */
public enum UserRole {
    /**
     * 管理员
     */
    ADMIN(1),
    /**
     * 超级管理员
     */
    SUPER_ADMIN(2),
    /**
     * 登录用户
     */
    NORMAL(0),
    ;

    @Getter
    private Integer role;

    UserRole(Integer role) {
        this.role = role;
    }

    public static UserRole roleOf(int role) {
        if (role == 1) {
            return ADMIN;
        } else if (role == 2) {
            return SUPER_ADMIN;
        }

        return NORMAL;
    }

    public static boolean superAdmin(String role) {
        return SUPER_ADMIN.name().equalsIgnoreCase(role);
    }

    public static boolean superAdmin(Integer role) {
        return SUPER_ADMIN.role.equals(role);
    }
}
